function R = lawsmask_features(image)
if size(image,3) == 3
    image = rgb2gray(image);
end
image = double(image);
l3_1=processGroup(image, [-1 0 1]);
l3_2=processGroup(image, [-1 2 -1]);
l5_1=processGroup(image, [-1 -2 0 2 1]);
l5_2=processGroup(image, [-1 0 2 0 -1]);
l5_3=processGroup(image, [-1 2 0 -2 1]);
l5_4=processGroup(image, [1 -4 6 -4 1]);
l7_1=processGroup(image, [-1 -4 -5 0 5 4 1]);
l7_2=processGroup(image, [-1 -2 1 4 1 -2 -1]);
l7_3=processGroup(image, [-1 0 3 0 -3 0 1]);
l7_4=processGroup(image, [1 -2 -1 4 -1 -2 1]);
l7_5=processGroup(image, [-1 6 -15 20 -15 6 -1]);
e2_1=processGroup(image, [-1 1]);
e4_1=processGroup(image, [1 -3 3 -1]);
e6_1=processGroup(image, [1 -3 2 2 -3 1]);
R = [l3_1 l3_2, ...
    l5_1 l5_2 l5_3 l5_4, ...
    l7_1 l7_2 l7_3 l7_4 l7_5, ...
    e2_1 e4_1 e6_1];
end

function g = processGroup(image, filt)
%if sum(filt(:)) ~= 0
%    error('wrong value?');
%end

r_h = filter2(filt, image) - image;
r_v = filter2(filt', image) - image;
r_hv = filter2(filt'*filt, image) - image;
r_min = min(min(r_h, r_v), r_hv);
r_max = max(max(r_h, r_v), r_hv);

%MAPPING = getmapping(8, 'u2');
f_h = [locp(r_h, 1, 8, 'nh')];
f_v = [locp(r_v, 1, 8, 'nh')];
f_hv = [locp(r_hv, 1, 8, 'nh')];
f_max = [locp(r_max, 1, 8, 'nh')];
f_min = [locp(r_min, 1, 8, 'nh')];
g = [f_h f_v f_hv f_max f_min];
end
